import * as types from '../constants/ActionTypes';

const initState = {
    recharge_record_status : 0, 
    message : '加载中', 
    results : []
};

export default function rechargerecord(state = initState, action = {}) {
    const {
        type, payload
    } = action;
    switch (type) {
        case types.FETCH_RECHARGE_RECORDS:
            let start = payload.start;
            if (start <= 1) {
               state.results = [];
            }
            return { ...state, ...payload };
    	
        case types.FETCH_RECHARGE_RECORDS_SUCCESS:
            let successData = {
                recharge_record_status : 1,
                message : "加载充值记录成功",
                results : state.results.concat(payload.results)
            };
            return successData;

        case types.FETCH_RECHARGE_RECORDS_FAILURE:
            let failureData = {
                recharge_record_status : -1,
                message : "加载充值记录失败",
                results : state.results
            };

            return failureData;
        case types.RESET_RECHARGE_RECORDS:
            return { ...payload }

        default:
            return state;
    }
}